package com.ecr.hub.database.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import com.ecr.hub.model.enumeration.HubUserRole;
import com.ecr.hub.model.user.Role;
import com.ecr.hub.model.user.User;

public class MapperUser {

	protected static ParameterizedRowMapper<User> mapperUser = new ParameterizedRowMapper<User>() {
		public User mapRow(ResultSet rs, int rowNum) throws SQLException {
			User user = new User();
			user.setPasswordConfirm(rs.getString("password"));
			user.setAskForPassword(rs.getBoolean("new_password"));
			user.setCreationDate(rs.getDate("creation_date"));
			user.setFirstName(rs.getString("first_name"));
			user.setLastName(rs.getString("last_name"));
			user.setPassword(rs.getString("password"));
			user.setLogin(rs.getString("login"));
			user.setComment(rs.getString("comment"));
			user.setActive(rs.getBoolean("active"));
			user.setIndelible(rs.getBoolean("indelible"));
			user.setSessionId(rs.getString("session_id"));
			user.setId(rs.getInt("id"));

			Role role = new Role();
			role.setId(rs.getInt("id_role"));
			role.setRole(HubUserRole.valueOf(rs.getString("role_user")));
			role.setLabel(rs.getString("label"));
			user.setRole(role);
			return user;
		}
	};

	protected static ParameterizedRowMapper<Role> mapperRole = new ParameterizedRowMapper<Role>() {
		public Role mapRow(ResultSet rs, int rowNum) throws SQLException {
			Role role = new Role();
			role.setId(rs.getInt("id"));
			role.setRole(HubUserRole.valueOf(rs.getString("role")));
			role.setLabel(rs.getString("label"));
			return role;
		}
	};
}
